package collection;

import java.util.ArrayList;
import java.util.Collection;

/**
 * 集合只能存放引用类型元素，并且存放的是元素的引用(地址)
 */
public class CollectionDemo4 {
    public static void main(String[] args) {
        Collection c = new ArrayList();
        Point p = new Point(1,2);
        c.add(p);//将p的值(地址)存入集合c
        System.out.println("p:"+p);//(1,2)
        System.out.println("c:"+c);//[(1,2)]
        p.setX(2);
        System.out.println("p:"+p);//(2,2)
        System.out.println("c:"+c);//[(2,2)]   集合也会改到Point修改后的效果
        doSome(c,p);
        System.out.println("p:"+p);//(3,2)
        System.out.println("c:"+c);//[(3,2)]
    }
    public static void doSome(Collection c,Point p){
        p.setX(3);
        p = new Point(4,5);
        c = new ArrayList();
        c.add(p);
        p.setX(6);
    }
}
